<?php
namespace Admin\Controller;
use Think\Controller;
class CommonController extends Controller {

	public function _initialize(){
		
        //判断是否登录

        if(!session('?admin.admin_name'))
        {
            $this->redirect('Login/index');
        }
        else
        {
           //查询用户信息
            $character = M('admin a')->join('`character` c on c.id=a.character_id')->where('admin_name="'.session("admin.admin_name").'"')->getField('c.character');
            
            $this->assign('character',$character);

        }

        //判断权限
        //判断是否超级管理员
        $root = M('character')->getFieldById(session('admin.character_id'),'is_root');
        if($root)
        {   
            //获取控制器方法字段
            $controller = CONTROLLER_NAME;
            $action = ACTION_NAME;
            $rights_str = $controller.'-'.$action;
            // dump($rights_str);
            //获取当前用户权限字段
            $rights = M('character')->getFieldById(session('admin.character_id'),'rights');
            //转换成数组
            $arr = explode(',',$rights);
            // dump($arr);
            // 判断是否有该权限
            if(!in_array($rights_str,$arr))
            {
                $this->error('没有操作该功能权限!',U('Index/welcome1'));
            }
        }
        
    }
}
